import 'dart:convert';

import 'package:device_identity/device_identity.dart';
import 'package:new_yuqib_app/yqbConfig/storage_config.dart';
import 'package:new_yuqib_app/yqbConfig/yqb_base.dart';
import 'package:new_yuqib_app/yqbModel/apply_data_model.dart';
import 'package:package_info_plus/package_info_plus.dart';

///逾期帮App
class YqbApp {
  static late PackageInfo packageInfo;

  static Future init() async {
    packageInfo = await PackageInfo.fromPlatform();
  }

  //获取设备广告id
  static Future<String> get oaid async {
    String val = "";
    if(StorageConfig.oaid.isNotEmpty) return StorageConfig.oaid;
    await DeviceIdentity.register();
    do {
      val = await DeviceIdentity.oaid;
      if (val.isNotEmpty) {
        break;
      } else {
        await DeviceIdentity.register();
      }
    } while (val.isEmpty);
    return val;
  }

  ///小程序Id
  static String miniProgramID = "gh_7458ca4d9c09";

  ///是否跳转聊天
  static int ischat = 0;

  ///是否跳转小程序
  static int isXcx = 0;

  //跳转小程序
  static int jumpXcx = 0;

  ///小程序路径链接
  static miniProgramPath({required int id}) {
    return 'pages/PaymentSuccessful/PaymentSuccessful.html?video_id=$id&token=${StorageConfig.token}&app=$appName';
  }

  ///获取客服imID
  static setServiceData(ApplyDataModel data) {
    StorageConfig.services = jsonEncode(data.toJson());
  }

  ///获取客服ID
  static ApplyDataModel? getServiceData() {
    final data = StorageConfig.services;
    if (data.isEmpty) {
      return null;
    } else {
      return ApplyDataModel.fromJson(jsonDecode(data));
    }
  }

  ///注销
  static logOut() {
    StorageConfig;
  }
}
